<template>
  <div class="top">
    <div class="left">
      <span class="lbtn" @click="goHome">首页</span>
    </div>
    <div class="center">
      <div class="title">智慧旅游可视化大数据展示平台</div>
    </div>
    <div class="right">
      <span class="rbtn">统计报告</span>
      <span class="time">当前时间：{{ timeNow }}</span>
    </div>
  </div>
</template>

<script setup lang="ts">
import {useRouter} from "vue-router";
//@ts-ignore
import moment from 'moment'
import {ref, onMounted, onBeforeUnmount} from "vue";

//获取路由器对象
let $router = useRouter();
//存储当前的时间
let timeNow = ref<string>(moment().format('YYYY/MM/DD HH:mm:ss'));
//定时器
let timer = ref<number>(0)

//组件挂载完毕实时更新事件
onMounted(() => {
  timer.value = setInterval(() => {
    timeNow.value = moment().format('YYYY/MM/DD HH:mm:ss');
  }, 1000)
})

//组件销毁之前，清楚定时器
onBeforeUnmount(() => {
  clearInterval(timer.value);
})

//返回首页的回调
const goHome = () => {
  $router.push('/home')
}
</script>

<style scoped lang="scss">
.top {
  width: 100%;
  height: 40px;
  display: flex;

  .left {
    flex: 1;
    background: rgba(153, 169, 191, 0.36);

    .lbtn {
      width: 150px;
      height: 40px;
      float: right;
      text-align: center;
      line-height: 40px;
      background: rgba(8, 41, 0, 0.49);
      font-size: 20px;
      color: #29fcff;
    }
  }

  .center {
    flex: 2;

    .title {
      width: 100%;
      height: 70px;
      font-size: 50px;
      text-align: center;
      color: #29fcff;
      background: rgba(153, 169, 191, 0.36);
    }
  }


  .right {
    flex: 1;
    background: rgba(153, 169, 191, 0.36);
    display: flex;
    justify-content: space-between;
    align-items: center;

    .rbtn {
      width: 150px;
      height: 40px;
      float: left;
      line-height: 40px;
      background: rgba(8, 41, 0, 0.49);
      text-align: center;
      font-size: 20px;
      color: #29fcff;
    }

    .time {
      color: #29fcff;
      line-height: 40px;
      font-size: 15px;
      text-align: center;
      margin-right: 30px;
    }
  }
}
</style>